package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface DishMapper {

    Page<DishVO> pageQuery(DishPageQueryDTO dishPageQueryDTO);

    /**
     * 根据分类id查询菜品数量
     * @param categoryId
     * @return
     */
    @Select("select count(id) from dish where category_id = #{categoryId}")
    Integer countByCategoryId(Long categoryId);
    @AutoFill(value = OperationType.INSERT)
    void insert(Dish dish);


    void deleteBatches(List<Long> idList);
    @Select("select * from  dish where id =#{id}")
    Dish getById(Long id);
    @Delete("delete from dish where id =#{id};")
    void deleteById(Long id);
    @Update("update dish set status =#{status} where id =#{id} ")

    void updateDishStatus(int id, int status);
    List<DishVO> listWithFlavor(Dish dish);

    @Select("SELECT * FROM dish WHERE category_id = #{dish.categoryId} AND status = #{dish.status}")
    List<DishVO> getByDish(@Param("dish") Dish dish);
    @Select("select * from dish where category_id =#{categoryId}")
    List<Dish> getByCategoryId(long categoryId);
}
